//
//  LLProfileViewController.m
//  lrlzapp
//
//  Created by dl on 16/2/22.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLProfileViewController.h"
#import "LLProfileViewModel.h"
#import "LLTableViewCellStyleValue1.h"

@interface LLProfileViewController () <UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong, readwrite) LLProfileViewModel *viewModel;
@property(weak, nonatomic) IBOutlet UIView *headerView;
@property(weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation LLProfileViewController
@dynamic viewModel;

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.tableView registerClass:[LLTableViewCellStyleValue1 class] forCellReuseIdentifier:IDENTIFIER_TABLEVIEW_CELL_STYLE1];
    [self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
}

- (void)bindViewModel {
    self.viewModel = [[LLProfileViewModel alloc] init];
    [super bindViewModel];
    self.navigationItem.rightBarButtonItem.rac_command = self.viewModel.toSettingCommand;
    self.tableView.backgroundColor = UI_COLOR_BG_LIGHT_GREY;
    self.tableView.sectionIndexColor = [UIColor darkGrayColor];
    self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
    self.tableView.sectionIndexMinimumDisplayRowCount = 20;
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return section == 0 ? 2 : (section == 1 ? 2 : 1);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IDENTIFIER_TABLEVIEW_CELL_STYLE1 forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.separatorInset = UIEdgeInsetsZero;
    NSDictionary *dic = self.viewModel.profileTableDic[indexPath.section][indexPath.row];
    cell.imageView.image = [UIImage imageNamed:dic[@"img"]];
    cell.textLabel.text = dic[@"title"];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return SUIT_H(44);
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.viewModel.didSelectCommand execute:indexPath];
}

@end
